package cn.lxm.samples.resourceserver.controller;//package cn.lxm.samples.resouces_server_1.controller;
//
//import cn.lxm.oauth.resource_server.service.OauthToken;
//import cn.lxm.oauth.resource_server.service.WebService;
//import com.google.gson.Gson;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Controller;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.ResponseBody;
//
//import javax.servlet.http.Cookie;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * @author LXM
// * @Title: oauth
// * @Description:
// * @date 2018/8/9上午10:31
// */
//@Controller
//public class LoginController {
//
//    @Autowired
//    private WebService webService;
//
//    @GetMapping("/user/dologin")
//    @ResponseBody
//    public String doLogin(HttpServletRequest request, HttpServletResponse response) {
//
//        String userName = request.getParameter("username");
//        String password = request.getParameter("password");
//        Map map1 = new HashMap();
//        map1.put("username", userName);
//        map1.put("password", password);
//        map1.put("grant_type", "password");
//
//        //发送HTTP请求认证
//        try {
//            userName = webService.post("http://localhost:8080/oauth/token?grant_type=password&username=" + userName + "&password=" + password, null);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        OauthToken oauthToken = new Gson().fromJson(userName, OauthToken.class);
//        Cookie cookie = new Cookie("cookie_access_token", oauthToken.getAccess_token());
//        cookie.setHttpOnly(true);
//        cookie.setMaxAge(oauthToken.getExpires_in());
//        response.addCookie(cookie);
//        response.setHeader("Authorization", "bearer " + oauthToken.getAccess_token());
//        response.setHeader("Access-Control-Expose-Headers", "Authorization");
//        response.setHeader("Cache-Control","no-store");
//
//        return userName;
//
//    }
//
//    @RequestMapping("/user/login")
//    public String toLogin() {
//        return "login";
//    }
//
//
//    @RequestMapping("/user/index")
//    public String toIndex() {
//        return "index.html";
//    }
//
//}
